#!/usr/bin/env node
(async function() {
  var complete, fs, omelette;

  util = require('util');
  fs = require('fs');
  omelette = require("../src/omelette");
  // omelette`githubber|gh
  //             ${['pull', 'push', 'star']}
  //             ${() => fs.readdirSync("/Users/")}
  //             ${({ before }) => [
  //               `${before}/helloworld`,
  //               `${before}/blabla`]}
  //           `.init();
  complete = omelette("githubber-async|ghba|gha|ga <action> <user> <repo>");

  complete.on("action", async function({ reply }) {
    reply(new Promise((resolve) => {
      setTimeout(function () {
        resolve(["star","clone", "update", "push"]);
      }, 1000)
    }))
  });

  complete.on('user', async ({ reply }) => {
    reply(await util.promisify(fs.readdir)('/Users'))
  })

  complete.on("repo", function({ before, reply }) {
    var user = before;
    reply(["http://github.com/" + user + "/helloworld", "http://github.com/" + user + "/blabla"]);
  });

  // If you want to setup, you can use `omeletteInstance.setupShellInitFile()` function.
  if (~process.argv.indexOf('--setup')) {
    complete.setupShellInitFile();
  }

  complete.next(()=> {
    console.log("Your program's default workflow.");
    console.log(process.argv);
  });
  complete.init();
}).call(this);
